#include "conn.h"
#include "heap.h"
// TODO: how to handle server loop?
#ifndef SERVER_H
#define SERVER_H
class Server {
	int listener;
	Heap<c_id_t, Connection*> connections;
	Heap<c_id_t, Server*> servers;
	Heap<const char*, counter_t> counters;
	addr_t local_addr;
	port_t port;
	int protocol;
	long timeout;
	int sysErr;
	int appErr;
	unsigned int reconnect;
	/* Standard server architecture functionality */
	void addConnection(Connection* _conn);
	void spawn(Server* machine, Connection* _conn);
	void handleConnTimeout(c_id_t _conn_id);
public:
	Server(const char * _interface,
			port_t _port,
			int _proto,
			long _timeout,
			unsigned int _reconnect);
	Server(int _sock,
			const char * _interface,
			port_t _port,
			int _proto);
	/* User-defined server architecture functionality */
	virtual void handleNew();
	virtual void routine();
	virtual void handleError(int errno);
	int start();
	void closeConnection();
	void shutDown();
	/* Timer and Message functionality defined by user; auto-generated */
};
#endif
